//
// Created by thomas on 9/13/21.
//

#ifndef QBYTEARRAY_CIRCULARBUFFER_H
#define QBYTEARRAY_CIRCULARBUFFER_H

#include <algorithm> // for std::min

class CircularBuffer
{
public:
    explicit CircularBuffer(size_t capacity);

    ~CircularBuffer();

    size_t size() const { return size_; }

    size_t capacity() const { return capacity_; }

    bool isfull() const
    {
        return size_ == capacity_;
    }

    bool isempty() const
    {
        return size_ == 0;
    }

    void resize(size_t s);

    // Return number of bytes written.
    size_t write(const char *data, size_t bytes);

    // Return number of bytes read.
    size_t read(char *data, size_t bytes);


private:
    size_t beg_index_, end_index_, size_, capacity_;
    char *data_;
};


#endif //QBYTEARRAY_CIRCULARBUFFER_H
